
import { _decorator, Component, Node, EventTouch, Vec2, Prefab, instantiate } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('PlayerControl')
export class PlayerControl extends Component {
    @property
    score:number = 0
    
    @property(Prefab)
    bulletPrefab = null

    start() {
        this.node.on(Node.EventType.TOUCH_MOVE, (event: EventTouch) => {
            const loc: Vec2 = event.getLocation()
            this.node.setPosition(loc.x - 240, loc.y - 400, 0)
        })

        this.schedule(() => {
            const bullet: Node = instantiate(this.bulletPrefab)
            const pos = this.node.getPosition()
            bullet.setPosition(pos.x, pos.y + 100)
            bullet.parent = this.node.parent
        }, 0.1)
    }

    // update (deltaTime: number) {
    //     // [4]
    // }
}
